<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% 
String un = request.getParameter("uname");
String pw = request.getParameter("passwd");
String loginPage = "login.jsp";

//Mike Earl
//declare variables for customer info that will be used in the HTML;
String firstName = null;
String lastName = null;
String address = null;
String city = null;
String prov = null;
String postal = null;
String country = null;
String homePhone = null;
String busPhone = null;
String email = null;
String password = null;
String msg = "";
Connection conn = null;
Statement stmt = null;

String sql = "Select * from Customers where CustEmail='" + un + "' and CustPasswd='" + pw  + "'";
try {
	
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelexperts","root","root");
	stmt = conn.createStatement();
	ResultSet rs = stmt.executeQuery(sql);
	if (rs.next())
	{
		
		firstName = rs.getString(2);
		lastName = rs.getString(3);
		address = rs.getString(4);
		city = rs.getString(5);
		prov = rs.getString(6);
		postal = rs.getString(7);
		country = rs.getString(8);
		homePhone = rs.getString(9);
		busPhone = rs.getString(10);
		email = rs.getString(10);
		password = rs.getString(13);
		session.setAttribute("username", firstName);
	}
	else
	{
		response.sendRedirect("login.jsp");
	}
	
	}catch(Exception e) {
		
	}
finally {
	conn.close();
	stmt.close();
}

%>
<h1>Login handler</h1>
<h3>Hello <%out.println(un); %></h3>
</body>
</html>